﻿using aspNetCURD.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace aspNetCURD.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class StudentScCourseController : ControllerBase
    {
        private readonly IStudentScCourseRepository _studentScCourseRepository;
        public StudentScCourseController(IStudentScCourseRepository studentScCourseRepository)
        {
            _studentScCourseRepository = studentScCourseRepository;
        }
        /// <summary>
        /// 查询学生的课程及成绩
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStudentScCourses([FromQuery] string keyword)
        {
            var studentScCourseRepositorys = _studentScCourseRepository.GetStudentScCourses(keyword);
            if(studentScCourseRepositorys == null || studentScCourseRepositorys.Count() <= 0)
            {
                return NotFound("未找到学生成绩数据");
            }
            return Ok(studentScCourseRepositorys);
        }
    }
}
